<template>
	<view class="text-kaiti">
		<view class="search">
			<u-search placeholder="搜索或输入关键字" height="64" v-model="keyword" :action-style="{textAlign:'right'}" @search="search"></u-search>
		</view>
		<view class="tabs">
			<u-tabs name="name" :list="list" :current="current" @change="tabsChange" font-size="26" active-color="#000000"
			 :bar-style="{backgroundColor:'#c40200',height:'5rpx',borderRadius: '5rpx',width:'43rpx'}">
			</u-tabs>
			<view class="icon-list">
				<u-icon name="list" size="40"></u-icon>
			</view>
		</view>
		<block v-for="(item2,index2) in recommendData" :key="item2.id">
			<!-- 1张图 -->
			<img-text-list v-if="item2.dkdtp.length == 1" :item="item2" @hideData="hideData">
				<view class="img-1" @click="goCircleDetail(item2)">
					<image :src="$baseUrl + item2.dkdtp[0].lj" mode="aspectFill" lazy-load></image>
				</view>
			</img-text-list>
			<!-- 2张图 -->
			<img-text-list v-if="item2.dkdtp.length == 2" :item="item2" @hideData="hideData">
				<view class="img-4" style="margin-top: 10rpx;" @click="goCircleDetail(item2)">
					<image :src="$baseUrl + item2.dkdtp[0].lj" mode="aspectFill" lazy-load></image>
					<image :src="$baseUrl + item2.dkdtp[1].lj" mode="aspectFill" lazy-load></image>
				</view>
			</img-text-list>
			<!-- 3张图 -->
			<img-text-list v-if="item2.dkdtp.length == 3" :item="item2" @hideData="hideData">
				<view class="img" @click="goCircleDetail(item2)">
					<view class="img-left">
						<image :src="$baseUrl + item2.dkdtp[0].lj" mode="aspectFill" lazy-load></image>
					</view>
					<view class="img-right">
						<view class="img-right-list">
							<image :src="$baseUrl + item2.dkdtp[1].lj" mode="aspectFill" lazy-load></image>
						</view>
						<view class="img-right-list">
							<image :src="$baseUrl + item2.dkdtp[2].lj" mode="aspectFill" lazy-load></image>
						</view>
					</view>
				</view>
			</img-text-list>
			<!-- 4张图 -->
			<img-text-list v-if="item2.dkdtp.length == 4" :item="item2" @hideData="hideData">
				<view class="img-4" style="margin-top: 10rpx;" @click="goCircleDetail(item2)">
					<image :src="$baseUrl + item2.dkdtp[0].lj" mode="aspectFill" lazy-load></image>
					<image :src="$baseUrl + item2.dkdtp[1].lj" mode="aspectFill" lazy-load></image>
				</view>
				<view class="img-4" style="margin-top: 10rpx;" @click="goCircleDetail(item2)">
					<image :src="$baseUrl + item2.dkdtp[2].lj" mode="aspectFill" lazy-load></image>
					<image :src="$baseUrl + item2.dkdtp[3].lj" mode="aspectFill" lazy-load></image>
				</view>
			</img-text-list>
			<!-- 5张图 -->
			<img-text-list v-if="item2.dkdtp.length == 5" :item="item2" @hideData="hideData">
				<view class="img-2" @click="goCircleDetail(item2)">
					<image :src="$baseUrl + item2.dkdtp[0].lj" mode="aspectFill" lazy-load></image>
					<image :src="$baseUrl + item2.dkdtp[1].lj" mode="aspectFill" lazy-load></image>
					<image :src="$baseUrl + item2.dkdtp[2].lj" mode="aspectFill" lazy-load></image>
				</view>
				<view class="img-2" style="margin-top: 8rpx;" @click="goCircleDetail(item2)">
					<image :src="$baseUrl + item2.dkdtp[3].lj" mode="aspectFill" lazy-load></image>
					<image :src="$baseUrl + item2.dkdtp[4].lj" mode="aspectFill" lazy-load></image>
					<image src="" mode="" style="background-color: #fbfbfb;" lazy-load></image>
				</view>
			</img-text-list>
			<!-- 6张图 -->
			<img-text-list v-if="item2.dkdtp.length == 6" :item="item2" @hideData="hideData">
				<view class="img-2" @click="goCircleDetail(item2)">
					<image :src="$baseUrl + item2.dkdtp[0].lj" mode="aspectFill" lazy-load></image>
					<image :src="$baseUrl + item2.dkdtp[1].lj" mode="aspectFill" lazy-load></image>
					<image :src="$baseUrl + item2.dkdtp[2].lj" mode="aspectFill" lazy-load></image>
				</view>
				<view class="img-2" style="margin-top: 8rpx;" @click="goCircleDetail(item2)">
					<image :src="$baseUrl + item2.dkdtp[3].lj" mode="aspectFill" lazy-load></image>
					<image :src="$baseUrl + item2.dkdtp[4].lj" mode="aspectFill" lazy-load></image>
					<image :src="$baseUrl + item2.dkdtp[5].lj" mode="aspectFill" lazy-load></image>
				</view>
			</img-text-list>
		</block>
		<view class="publish" @click="goPublish()">
			<u-icon name="pen" custom-prefix="custom-icon" size="50" color="#fff"></u-icon>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import imgTextList from "./circle-comps/img-text-list.vue";
	import {
		commonGet
	} from "@/api/commonapi.js";
	export default {
		components: {
			imgTextList
		},
		data() {
			return {
				$baseUrl: "",
				keyword: "",
				list: [{
					name: "推荐"
				}],
				current: 0,
				swiperCurrent: 0,
				circleData: {},
				colid:"",
				recommendData: [], //推荐数据
				pagesize: 10
			}
		},
		onLoad() {
			this.$baseUrl = this.baseUrl
			this.getTabs()
			this.getCircle()
		},
		methods: {
			// tabs通知
			tabsChange(index) {
				this.current = index;
				this.colid = this.list[index].id
				this.getCircle(this.colid)
			},
			goCircleDetail(item2) {
				console.log(item2)
				uni.navigateTo({
					url: "/pages/circle/circle-detail/circle-detail?id=" + item2.id
				})
			},
			getCircle(colid, pagesize) {
				let _this = this
				let query = {
					ak: this.$store.state.token,
					cmd: "mDynamic_list_proc",
					para: JSON.stringify({
						pageindex: 1,
						pagesize: pagesize || 10,
						colid: colid,
						searchfull: this.keyword
					})
				}
				commonGet(query, (result) => {
					_this.recommendData = result.Data.Data
					result.Data.Data.forEach((item, index) => {
						item.dkdtp = JSON.parse(item.dkdtp)
					})
				})
			},
			getTabs() {
				let _this = this
				let query = {
					ak: this.$store.state.token,
					cmd: "mDynamic_list_proc",
					para: JSON.stringify({})
				}
				commonGet(query, (result) => {
					_this.list = _this.list.concat(result.Data.Datas2)
				})
			},
			onPullDownRefresh() {
				this.pagesize = 10
				this.getCircle(this.colid, this.pagesize)
				setTimeout(function() {
					uni.stopPullDownRefresh();
				}, 1000);
			},
			onReachBottom() {
				this.pagesize += 10
				this.getCircle(this.colid, this.pagesize)
			},
			// 搜索
			search() {
				this.getCircle(this.colid, 10)
			},
			hideData(e) {
				this.recommendData.forEach((item, index) => {
					if (item.id == e) {
						console.log(index)
						this.recommendData.splice(index, 1)
					}
				})
			},
			goPublish() {
				if (this.$store.state.token) {
					uni.navigateTo({
						url: "circle-publish/circle-publish"
					})
				} else {
					this.$refs.uToast.show({
						title: "请先登录",
						url: '/pages/myuser/user/UserInfo'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.search {
		padding: 80rpx 30rpx 20rpx 30rpx;
	}

	.tabs {
		padding: 0 30rpx 0 12rpx;
		color: #000 !important;
		border-bottom: 1px solid #ebebeb;
		position: relative;

		.icon-list {
			position: absolute;
			top: 50%;
			right: 30rpx;
			transform: translateY(-50%);
			width: 80rpx;
			height: 40rpx;
			text-align: right;
			background-image: linear-gradient(to right, rgba(255, 255, 255, 0), #fff, #fff);
			z-index: 10;
		}
	}

	.swiper-box {
		height: 0vh;
	}

	.swiper-item {
		padding-top: 12rpx;
		height: 100%;
	}

	.img {
		height: 320rpx;
		display: flex;
		border-radius: 20rpx;
		overflow: hidden;

		.img-left,
		.img-right-2 {
			width: 450rpx;
			height: 320rpx;

			image {
				width: 450rpx;
				height: 320rpx;
			}
		}

		.img-left,
		.img-left-2 {
			margin-right: 8rpx;
		}

		.img-right,
		.img-left-2 {
			width: 230rpx;
			height: 100%;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.img-right-list {
				width: 230rpx;
				height: 156rpx;

				image {
					width: 230rpx;
					height: 158rpx;
				}
			}
		}
	}

	.small-img,
	.img-2 {
		width: 100%;
		height: 156rpx;
		display: flex;
		justify-content: space-between;
		border-radius: 20rpx;
		overflow: hidden;
	}

	.small-img {
		image {
			height: 142rpx;
			width: 224rpx;
		}
	}

	.img-2 {
		height: 224rpx;

		image {
			height: 224rpx;
			width: 224rpx;
		}
	}

	.img-1 {
		width: 100%;
		height: 320rpx;
		overflow: hidden;
		border-radius: 20rpx;

		image {
			width: 100%;
			height: 320rpx;
		}
	}

	.img-4 {
		width: 100%;
		height: 216rpx;
		border-radius: 20rpx;
		overflow: hidden;
		display: flex;
		justify-content: space-between;

		image {
			width: 340rpx;
			height: 216rpx;
		}
	}

	.publish {
		position: fixed;
		bottom: 204rpx;
		right: 35rpx;
		width: 100rpx;
		height: 100rpx;
		border-radius: 100%;
		background-color: #c40200;
		display: flex;
		justify-content: center;
		align-items: center;
	}
</style>
